import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../common/widgets/fan_gradient.dart';
import '../../common/widgets/progress_horizontal.dart';
import '../../common/widgets/progress_ring.dart';

class AnalyseResultPage extends StatefulWidget {
  const AnalyseResultPage({super.key});

  @override
  State<AnalyseResultPage> createState() => _AnalyseResultPageState();
}

class _AnalyseResultPageState extends State<AnalyseResultPage> {
  double progress = 0.66;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        title: const Text("分析结果"),
      ),
      body: Stack(
        fit: StackFit.expand,
        children: [
          const DecoratedBox(
              decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [
            Color(0xffFDF2F8),
            Color(0xffFAF5FF),
          ]))),
          Padding(
            padding: EdgeInsets.all(20.w),
            child: SafeArea(
              bottom: false,
                child: SingleChildScrollView(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const Text(
                    "当前处于暧昧期",
                    style: TextStyle(color: Color(0xff010204), fontSize: 18),
                  ),
                  const Text(
                    "好感初现、试探互动、不确定感",
                    style: TextStyle(color: Color(0xff5C495D), fontSize: 14),
                  ),
                  const SizedBox(
                    height: 20,
                  ),
                  SizedBox(
                    width: double.infinity,
                    height: 200,
                    child: Stack(
                      fit: StackFit.expand,
                      children: [
                        Center(
                          child: FanGradientWidget(
                            colors: [
                              Color(0xffC084FC).withOpacity(0.2),
                              Color(0xffC084FC).withOpacity(0.15),
                              Color(0xffC084FC).withOpacity(0.1),
                              Color(0xffC084FC).withOpacity(0.05),
                              Color(0xffF9A8D4).withOpacity(0.01)
                            ],
                            direction: FanDirection.topLeft,
                            sweepAngle: pi / 2,
                            innerRadius: 50,
                          ),
                        ),
                        Center(
                          child: ProgressRing(
                            progress: progress,
                            size: 200,
                            strokeWidth: 15,
                            showShadow: false,

                            animationDuration: const Duration(milliseconds: 1200),
                            gapAngle: 2.4, // 开口大小
                            gapDirection: GapDirection.bottom, // 可变开口方向
                            gradientColors: const [
                              Color(0xffC184FB), // 紫色
                              Color(0xffC9FDF9), // 蓝色
                              Color(0xffF473B7), // 青色
                              Color(0xFFFF6B9D), // 粉色
                            ],
                            backgroundColor: Colors.white,
                          ),
                        )
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 20,
                  ),
                  const Row(
                    children: [
                      Expanded(
                        child: AspectRatio(
                          aspectRatio: 1.8,
                          child: HaoGanDuWidget(),
                        ),
                      ),
                      SizedBox(
                        width: 15,
                      ),
                      Expanded(
                        child: AspectRatio(
                          aspectRatio: 1.8,
                          child: HaoGanDuWidget(),
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(
                    height: 20,
                  ),
                  const FenXiShuoMing(),
                  const SizedBox(
                    height: 20,
                  ),
                  const FenXiShuoMing(),
                  const SizedBox(
                    height: 20,
                  ),
                  const FenXiShuoMing(),
                  const SafeArea(top: false,child: SizedBox.shrink(),)
                ],
              ),
            )),
          )
        ],
      ),
    );
  }
}

class HaoGanDuWidget extends StatelessWidget {
  const HaoGanDuWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(15),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15)),
      child: const Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text(
                "好感度",
                style: TextStyle(
                    color: Color(0xff4B5563), fontSize: 13.4, fontWeight: FontWeight.w500),
              ),
              Spacer(),
              Text(
                "66%",
                style: TextStyle(color: Color(0xff5C495D), fontSize: 14),
              ),
            ],
          ),
          HorizontalProgressBar(
            progress: 0.5,
            width: double.infinity,
            height: 8,
            showPercentage: false,
            borderRadius: 15,
            gradientColors: [
              Color(0xffF472B6),
              Color(0xffC084FC),
            ],
          ),
          Text(
            "86%",
            style: TextStyle(color: Color(0xff1F2937), fontSize: 17, fontWeight: FontWeight.w500),
          )
        ],
      ),
    );
  }
}

class FenXiShuoMing extends StatelessWidget {
  const FenXiShuoMing({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 11),
      width: double.infinity,
      decoration: BoxDecoration(
          gradient: const LinearGradient(colors: [
            Color(0xffFEE8FF),
            Colors.white,
          ]),
          borderRadius: BorderRadius.circular(12),
          border: Border.all(width: 4, color: Colors.white)),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Stack(
                children: [
                  Text(
                    "你的分析说明",
                    style: TextStyle(
                        color: Color(0xff010204), fontWeight: FontWeight.bold, fontSize: 17),
                  ),
                  Positioned(
                      left: 0,
                      right: 0,
                      bottom: 0,
                      child: Container(
                        height: 8,
                        decoration: BoxDecoration(
                            gradient: LinearGradient(colors: [
                          Color(0xffF472B6),
                          Color(0xffC184FB).withOpacity(0),
                        ])),
                      ))
                ],
              )
            ],
          ),
          const SizedBox(
            height: 11,
          ),
          const Text(
            "根据聊天记录分析，你在关系中表现积极主动，经常关心对方，但有时会显得过于急切。建议在表达感情时可以更加温和。",
            style: TextStyle(
                height: 1.1, color: Color(0xff5C495D), fontSize: 15, fontWeight: FontWeight.w500),
          )
        ],
      ),
    );
  }
}
